﻿using BBI.Model;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BBI.Data
{
    public class ArticleConfiguration : EntityTypeConfiguration<Article>
    {
        public ArticleConfiguration()
        {
            this.HasKey(p => p.ArticleId);

            this.Property(p => p.ArticleId)
                .HasColumnName("ArticleId")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("art_Articles");

            this.Property(p => p.Title).HasMaxLength(100).IsRequired();  
            this.Property(p => p.CategoryId).IsRequired();
            this.Property(p => p.ImageUrl).HasMaxLength(150).IsOptional();
            this.Property(p => p.KeyWords).HasMaxLength(100).IsOptional(); 
            this.Property(p => p.ViewCount).IsRequired();
            this.Property(p => p.AddedDate).IsRequired().HasColumnType("datetime");
            this.Property(p => p.AddedBy).HasMaxLength(50);
            this.Property(p => p.UpdatedDate).IsOptional().HasColumnType("datetime");
            this.Property(p => p.UpdatedBy).IsOptional().HasMaxLength(50);

            this.HasRequired(p => p.Category)
            .WithMany(h=>h.Articles)
            .HasForeignKey(p => p.CategoryId);  
        }
    }
}
